<HTML><HEAD><TITLE>setbit(+Number, +Index, -Result)</TITLE>
</HEAD><BODY>[ <A HREF="index.html">Arithmetic</A> | <A HREF="../../index.html">Reference Manual</A> | <A HREF="../../fullindex.html">Alphabetic Index</A> ]
<H1>setbit(+Number, +Index, -Result)</H1>
Result is Number with the Index'th bit set.


<DL>
<DT><EM>Number</EM></DT>
<DD>Integer.
</DD>
<DT><EM>Index</EM></DT>
<DD>Non-negative integer.
</DD>
<DT><EM>Result</EM></DT>
<DD>A variable or integer.
</DD>
</DL>
<H2>Description</H2>
   Set the Index'th bit in Number giving Result. The least significant
   bit has index zero. Two's complement representation is assumed.
   This predicate is used by the ECLiPSe compiler to expand evaluable
   arithmetic expressions.  So the call to setbit(Number, Index, Result) is
   equivalent to
<PRE>
    Result is setbit(Number, Index)
</PRE>
   which should be preferred.
<P>
   In coroutining mode, if Number or Index are uninstantiated, the call
   is delayed until these variables are instantiated.

<H3>Modes and Determinism</H3><UL>
<LI>setbit(+, +, -) is det
</UL>
<H3>Exceptions</H3>
<DL>
<DT><EM>(4) instantiation fault </EM>
<DD>Number or Index is not instantiated (non-coroutining mode    only).
<DT><EM>(5) type error </EM>
<DD>Number or Index is a number but not an integer.
<DT><EM>(24) number expected </EM>
<DD>Number or Index is not of a numeric type.
</DL>
<H2>Examples</H2>
<PRE>
Success:
      setbit(0, 3, 8).
      setbit(1, 8, X).             gives X=257.
      X is setbit(setbit(0,3),5).  gives X=40.



</PRE>
<H2>See Also</H2>
<A HREF="../../kernel/arithmetic/is-2.html">is / 2</A>, <A HREF="../../kernel/arithmetic/clrbit-3.html">clrbit / 3</A>, <A HREF="../../kernel/arithmetic/getbit-3.html">getbit / 3</A>
</BODY></HTML>
